//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.mingsoft.mdiy.action;

import java.util.List;
import java.util.MissingResourceException;
import java.util.stream.Collectors;
import net.mingsoft.basic.constant.e.SessionConstEnum;
import net.mingsoft.basic.strategy.IModelStrategy;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.mdiy.util.ConfigUtil;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseAction extends net.mingsoft.basic.action.BaseAction {
    @Autowired
    private IModelStrategy modelStrategy;

    public BaseAction() {
    }

    protected String getResString(String key) {
        String str = "";

        try {
            str = super.getResString(key);
        } catch (MissingResourceException var4) {
            str = this.getLocaleString(key, "net.mingsoft.mdiy.resources.resources");
        }

        return str;
    }

    protected boolean getPermissions(String masterPermission, String permission) {
        int size = ((List)this.modelStrategy.list().stream().filter((model) -> {
            return masterPermission.equalsIgnoreCase(model.getModelUrl());
        }).collect(Collectors.toList())).size();
        if (size <= 0) {
            size = ((List)this.modelStrategy.list().stream().filter((model) -> {
                return permission.equalsIgnoreCase(model.getModelUrl());
            }).collect(Collectors.toList())).size();
            if (size <= 0) {
                return false;
            }
        }

        return true;
    }

    protected boolean checkRandCode() {
        return this.checkRandCode(SessionConstEnum.CODE_SESSION.toString());
    }

    protected boolean checkRandCode(String param) {
        boolean checkCode = ConfigUtil.getBoolean("后台开发配置", "webCheckCode", true);
        if (!checkCode) {
            return true;
        } else {
            String sessionCode = this.getRandCode();
            String requestCode = BasicUtil.getString(param);
            this.LOG.debug("session_code:" + sessionCode + " requestCode:" + requestCode);
            if ("null".equals(sessionCode)) {
                return false;
            } else if (sessionCode.equalsIgnoreCase(requestCode)) {
                BasicUtil.removeSession(SessionConstEnum.CODE_SESSION);
                return true;
            } else {
                return false;
            }
        }
    }
}
